<?php
class IndexAction extends CommonAction {
	// 框架首页
	public function index() {
		ob_clean();

		$this->_checkUser();
		$this->_Config_name();//调用参数
		C ( 'SHOW_RUN_TIME', false ); // 运行时间显示
		C ( 'SHOW_PAGE_TRACE', false );
		$fck = D ('Fck');

		$id = $_SESSION[C('USER_AUTH_KEY')];
		$field = '*';
		$fck_rs = $fck -> field($field) -> find($id);
		
		
		
		
		$promo= M('promo');
		
		
		$pro=$promo->where('uid='.$id)->find();
		$prom=$pro['up_level'];
		
		$this->assign('pro',$prom);
		
		
			
		
		//未读邮件
		$msg= M('msg');
		
		
		
		$you['s_uid']=$id;
		$you['s_read']=0;
		$xiang=$msg->where($you)->count();
		if($xiang>0){
		
		$this->assign('you',$xiang);
		
		}
		
		//查询是否是报单中心
		
		$baodan=$fck->where('id='.$id)->find();
		
		$bao=$baodan['baodanhao']; 
		
		
	
		
		$this->assign('bao',$bao);
		
	
		
		
		$reid = $fck_rs['re_id'];
		$rers = $fck->where('id='.$reid)->field('user_tel')->find();
		
		$webcount = $fck->where('id>0')->count();
		$this->assign('webcount',$webcount);
		
		$reusertel = $rers['user_tel'];
		$this->assign('reusertel',$reusertel);

		$HYJJ="";
		$this->_levelConfirm($HYJJ,1);
		$this->assign('voo',$HYJJ);//会员级别

		$this->assign('fck_rs',$fck_rs);

		$fck->emptyMonthTime();
		$fck->getLevel();

		$ydate = strtotime(date('Y-m-d'));//当天时间
		$end_date =$ydate + (24*3600);//当天结束时间

		$fee_rs = M('fee')->field('s2,i4,str29,str3')->find();
		$fee_i4 = $fee_rs['i4'];
		$gg = $fee_rs['str29'];
		$b_money = $fee_rs['str3'];
		$this -> assign('gg',$gg);
		$this -> assign('b_money',$b_money);
		$this -> assign('fee_i4',$fee_i4);
		
		$map = array();
		$map['s_uid']   = $id;   //会员ID
		$map['s_read'] = 0;     // 0 为未读
        $info_count = M ('msg') -> where($map) -> count(); //总记录数
		$this -> assign('info_count',$info_count);

		$arss = $this->_cheakPrem();
        $this->assign('arss',$arss);
        
        $Guzhi = A("Guzhi");
        $Guzhi->stock_past_due();
        
		$fck -> mr_fenhong(1);
		$this->aotu_clearings();
		$this->checkfutou($id);			//检查是否复投
		
		//提供接收百分比
		
			$fee=M('fee');
		
		$fee_s = $fee->field('*')->find();
		$s24 = $fee_s['s24'];
		$s91 = explode('|',$s24);
         $this->assign('ti',$s91[0]);
          $this->assign('tii',$s91[1]);
          
          //钱包支出
          $bonus=M('bonushistory');
         // $one['uid']=$id;
         // $one['action_type']=5;
         // $zhicu=$bonus->where($one)->select();
         // $this->assign('zhicu',$zhicu);
       
          
           //钱包收入
          $two['uid']=$id;
          $two['action_type']=6;
        //  $zhicu1=$bonus->where($two)-> select();
        // $this->assign('zhicu1',$zhicu1);
         
         //echo $bonus->getLastSql($zhicu1);  
         // dump($zhicu1); exit;
          
          //支出分页
       	$where= array();
		$where['uid'] = $id;
		$where['action_type']=array('EQ','5');  
		  
		$field  = '*';
		//=====================分页开始==============================================
		import ( "@.ORG.ZQPage" );  //导入分页类
		$count = $bonus->where($where)->count();//总页数
		$listrows = 10;//每页显示的记录数
		$Page = new ZQPage($count,$listrows,1);
		//===============(总页数,每页显示记录数,css样式 0-9)
		$show = $Page->show();//分页变量
		$this->assign('page',$show);//分页变量输出到模板
		$zhicu=$bonus->where($one)->select();
		
		$list = $bonus->where($where)->field($field)->order('id desc')->page($Page->getPage().','.$listrows)->select();
		$this->assign('zhicu',$list);//数据输出到模板
		//收入分页
      
			$where1= array();
		$where1['uid'] = $id;
		$where1['action_type']=array('EGT','6');  
		  
		$field  = '*';
		//=====================分页开始==============================================
		import ( "@.ORG.ZQPage" );  //导入分页类
		$count = $bonus->where($where1)->count();//总页数
		$listrows = 10;//每页显示的记录数
		$Page = new ZQPage($count,$listrows,1);
		//===============(总页数,每页显示记录数,css样式 0-9)
		$show = $Page->show();//分页变量
		$this->assign('page1',$show);//分页变量输出到模板
		$list1 = $bonus->where($where1)->field($field)->order('id desc')->page($Page->getPage().','.$listrows)->select();
		$this->assign('zhicu1',$list1);//数据输出到模板
          
		
		
		
		
		$ydate = strtotime(date('Y-m-d'));//当天时间
		$end_date =$ydate + (30*24*3600);//当天结束时间
		
		
		
		
		//投资奖
		 $touzi=M('Touzi');
     $cash=M('Cash');
    $bshty = M ('bonushistory');
		
		$beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));                //获取每个月月初时间
        $endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));      // 获取每个月未时间
	    $now=date('d');      //今天 时间
	
      $time =  date('d',$endThismonth); 
     
   $shop = $touzi->where('user_id='.$id)->field('pay')->find();
 
  
if($now==1){

    $touzi->where('user_id='.$id)->delete();

// $touzi->execute("update __TABLE__ set  pay='null' where user_id=".$id);

}

//调用后台设置的投资奖

         $fee = M('fee');
    	$fee_rs = $fee->field('s23')->find(1);
    	$s23 = explode("|",$fee_rs['s23']);
    	

  
if(empty($shop)){

 if($now==$time){         //当今天时间等于月未时间
   
     $data2['uid']=$id;
     $data2['s_type']=0;
     
     $shop = $cash->where($data2)->sum('money');
     

  if($shop>30000 && $shop<50000){

     $data['user_id']=$id;
     $data['name']='投资奖';
     $data['money']=$s23[0];
     $data['time']=time();
     $data['pay']=1;
     $touzi->Add($data);
     
      $data3['uid']=$id;
     $data3['pdt']=time();
     $data3['prep']=$s23[0];
     $data3['allp']=$s23[0];
     $data3['bz']='投资奖';
     $data3['type']=1;
     $bshty->add($data3);
	 $fck->execute("update __TABLE__ set touzi=touzi+".$s23[0]." where id=".$id);
     
     }
     
  elseif($shop>50000 && $shop<80000){
     $data['user_id']=$id;
     $data['name']='投资奖';
     $data['money']=$s23[1];
     $data['time']=time();
     $touzi->Add($data);
     
     $data3['uid']=$id;
     $data3['pdt']=time();
     $data3['prep']=$s23[1];
     $data3['allp']=$s23[1];
     $data3['bz']='投资奖';
     $data3['type']=1;
     $bshty->add($data3);
    
	 $fck->execute("update __TABLE__ set touzi=touzi+".$s23[1]." where id=".$id);
     
      
      }
      
 elseif($shop>80000){
      
     $data['user_id']=$id;
     $data['name']='投资奖';
     $data['money']=$s23[2];
     $data['time']=time();
     $touzi->Add($data);
     
     $data3['uid']=$id;
     $data3['pdt']=time();
     $data3['prep']=$s23[2];
     $data3['allp']=$s23[2];
     $data3['bz']='投资奖';
     $data3['type']=1;
     $bshty->add($data3);
   
	$fck->execute("update __TABLE__ set touzi=touzi+".$s23[2]." where id=".$id);
     
      }
      
     }
  
}

		$this->display('index');
	}

    //每日自动结算
	public function aotu_clearings(){
		$fck = D ('Fck');
		$fee = M ('fee');
		$nowday = strtotime(date('Y-m-d'));
		$nowweek = date("w");
		if($nowweek==0){
			$nowweek = 7;
		}
		$kou_w = $nowweek-1;
		$weekday = $nowday-$kou_w*24*3600;
		
		$now_dtime = strtotime(date("Y-m-d"));
		if(empty($_SESSION['auto_cl_ok'])||$_SESSION['auto_cl_ok']!=$now_dtime){
			$js_c = $fee->where('id=1 and f_time<'.$weekday)->count();
			if($js_c>0){
				//经理分红
				$fck->jl_fenghong();
			}
			$_SESSION['auto_cl_ok'] = $now_dtime;
		}
		unset($fck,$fee);
	}
	public function checkfutou($id){
	//$fck = D ('Fck');
	//$cash=D ('cash');
	//$cashpp=D ('cashpp');
	//$id=$id;
	//$w['is_pay']=1;
	//$w['is_buy']=2;
	//$w['bid']=$id;
	//$res=$cashpp->where($w)->field('okdt')->order('okdt desc')->limit(1)->find();
	//$okdt=$res['okdt'];
	//$now=time();
	//$newt=$now-$okdt;
	//if($newt>172800){
	//$res=$fck->execute("update __TABLE__ set is_pay=0 where id=".$id);
	//if($res){
	//echo "<script>alert('您的帐号已经被暂时锁定，请重新激活');</script>";
	//$bUrl = __APP__.'/Public/login';
	//$this->_boxx($bUrl);
	//exit;
	//}
	//}
	}
}
?>